package org.ziwei.paipan.biao;

import org.ziwei.paipan.var.DiZhi;

/**
 * 紫微星系表
 * 五行局每一局有一个局数图，表示一个月三十天中紫微星落在命盘不同宫中
 * 根据出生日期和五行局查局数图中紫微星落在哪一宫
 * 比如癸丑年五月十七日生人，为金四局，在金四局的局数图中，查处十七日紫微星落卯宫
 * 
 * 紫微星是北斗星曜的主星
 * 跟着紫微星旋转的星曜一共六个：紫微星，天机星，太阳星，武曲星，天同星，廉贞星
 * 在命盘中逆向排列，口诀：
 * 紫微逆去宿天机，隔一太阳武曲移
 * 天同隔二廉贞位，空三复见紫微池
 * 
 */
public class ZiWeiXingBiao {
	
	/**
	 * 根据局数图，计算出紫微星表
	 * 根据五行局数和出生日定紫微星宫位，横轴出生日，纵轴五行局数
	 */
	private static DiZhi[][] ziWeiXingBiao = {
		{DiZhi.CHOU,DiZhi.CHEN,DiZhi.HAI,DiZhi.WU,DiZhi.YOU},
        {DiZhi.YIN,DiZhi.CHOU,DiZhi.CHEN,DiZhi.HAI,DiZhi.WU},
        {DiZhi.YIN,DiZhi.YIN,DiZhi.CHOU,DiZhi.CHEN,DiZhi.HAI},
        {DiZhi.MAO,DiZhi.SI,DiZhi.YIN,DiZhi.CHOU,DiZhi.CHEN},
        {DiZhi.MAO,DiZhi.YIN,DiZhi.ZI,DiZhi.YIN,DiZhi.CHOU},
        {DiZhi.CHEN,DiZhi.MAO,DiZhi.SI,DiZhi.WEI,DiZhi.YIN},
        {DiZhi.CHEN,DiZhi.WU,DiZhi.YIN,DiZhi.ZI,DiZhi.XU},
        {DiZhi.SI,DiZhi.MAO,DiZhi.MAO,DiZhi.SI,DiZhi.WEI},
        {DiZhi.SI,DiZhi.CHEN,DiZhi.CHOU,DiZhi.YIN,DiZhi.CHOU},
        {DiZhi.WU,DiZhi.WEI,DiZhi.WU,DiZhi.MAO,DiZhi.SI},
        {DiZhi.WU,DiZhi.CHEN,DiZhi.MAO,DiZhi.SHEN,DiZhi.YIN},
        {DiZhi.WEI,DiZhi.SI,DiZhi.CHEN,DiZhi.CHOU,DiZhi.MAO},
        {DiZhi.WEI,DiZhi.SHEN,DiZhi.YIN,DiZhi.WU,DiZhi.HAI},
        {DiZhi.SHEN,DiZhi.SI,DiZhi.WEI,DiZhi.MAO,DiZhi.SHEN},
        {DiZhi.SHEN,DiZhi.WU,DiZhi.CHEN,DiZhi.CHEN,DiZhi.CHOU},
        {DiZhi.YOU,DiZhi.YOU,DiZhi.SI,DiZhi.YOU,DiZhi.WU},
        {DiZhi.YOU,DiZhi.WU,DiZhi.MAO,DiZhi.YIN,DiZhi.MAO},
        {DiZhi.XU,DiZhi.WEI,DiZhi.SHEN,DiZhi.WEI,DiZhi.CHEN},
        {DiZhi.XU,DiZhi.XU,DiZhi.SI,DiZhi.CHEN,DiZhi.ZI},
        {DiZhi.HAI,DiZhi.WEI,DiZhi.WU,DiZhi.SI,DiZhi.YOU},
        {DiZhi.HAI,DiZhi.SHEN,DiZhi.CHEN,DiZhi.XU,DiZhi.YIN},
        {DiZhi.ZI,DiZhi.HAI,DiZhi.YOU,DiZhi.MAO,DiZhi.WEI},
        {DiZhi.ZI,DiZhi.SHEN,DiZhi.WU,DiZhi.SHEN,DiZhi.CHEN},
        {DiZhi.CHOU,DiZhi.YOU,DiZhi.WEI,DiZhi.SI,DiZhi.SI},
        {DiZhi.CHOU,DiZhi.ZI,DiZhi.SI,DiZhi.WU,DiZhi.CHOU},
        {DiZhi.YIN,DiZhi.YOU,DiZhi.XU,DiZhi.HAI,DiZhi.XU},
        {DiZhi.YIN,DiZhi.XU,DiZhi.WEI,DiZhi.CHEN,DiZhi.MAO},
        {DiZhi.MAO,DiZhi.CHOU,DiZhi.SHEN,DiZhi.YOU,DiZhi.SHEN},
        {DiZhi.MAO,DiZhi.XU,DiZhi.WU,DiZhi.WU,DiZhi.SI},
        {DiZhi.CHEN,DiZhi.HAI,DiZhi.HAI,DiZhi.WEI,DiZhi.WU}};
	
	/**
	 * 根据出生日期和五行局数，返回紫微星所在宫干
	 * @param day 出生日期
	 * @param wuXingNum 五行局数
	 * @return DiZhi
	 */
	public static DiZhi anZiWeiXing(int day, int wuXingNum){
		return ziWeiXingBiao[day-1][wuXingNum-2];
	}
	
	
	/**
	 * 根据紫微星所在宫支，返回天机星所在宫支
	 * @param diZhi 宫支
	 * @return DiZhi
	 */
	public static DiZhi anTianJiXing(DiZhi diZhi){
		return DiZhi.values()[(12 + diZhi.ordinal() -1 )%12];
	}
	
	/**
	 * 根据紫微星所在宫支，返回太阳星所在宫支
	 * @param diZhi 宫支
	 * @return DiZhi
	 */
	public static DiZhi anTaiYangXing(DiZhi diZhi){
		return DiZhi.values()[(12 + diZhi.ordinal() - 3)%12];
	}
	
	/**
	 * 根据紫微星所在宫支，返回武曲星所在宫支
	 * @param diZhi 宫支
	 * @return DiZhi
	 */
	public static DiZhi anWuQuXing(DiZhi diZhi){
		return DiZhi.values()[(12 + diZhi.ordinal() - 4)%12];
	}
	
	/**
	 * 根据紫微星所在宫支，返回天同星所在宫支
	 * @param diZhi 宫支
	 * @return DiZhi
	 */
	public static DiZhi anTianTongXing(DiZhi diZhi){
		return DiZhi.values()[( 12 + diZhi.ordinal() - 5)%12];
	}
	
	/**
	 * 根据紫微星所在宫支，返回廉贞星所在宫支
	 * @param diZhi 宫支
	 * @return DiZhi
	 */
	public static DiZhi anLianZhenXing(DiZhi diZhi){
		return DiZhi.values()[(12 + diZhi.ordinal() - 8)%12];
	}
}
